package com.androidexample.broadcastreceiver;

import java.text.SimpleDateFormat;
import java.util.Date;

import procesador.ProcesadorSMS;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
import android.database.Cursor;


public class BroadcastNewSms extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
//		super.onCreate(savedInstanceState);
//		setContentView(R.layout.androidexample_broadcast_newsms);
		 super.onCreate(savedInstanceState);
	     TextView view = new TextView(this);
	     Uri uriSMSURI = Uri.parse("content://sms/inbox");
	     Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
	     String sms = "";
	     System.out.println("+++++++++++++++++++++++++++++");
	     int idColumn = cur.getColumnIndex("_id");
         int dateColumn = cur.getColumnIndex("date");
         int numberColumn = cur.getColumnIndex("address");
         int bodyColumn = cur.getColumnIndex("body");
         SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
         
	     while (cur.moveToNext()) {
	      if(cur.getString(2).equals("7270") ){
	    	  sms += "From : SCOTIABANK : Importe S/. " +
	    			 ( new ProcesadorSMS().extraerImporte(cur.getString(bodyColumn)))+
	    			 " fecha="+sdf.format(new Date(Long.parseLong(cur.getString(dateColumn)))).toString()+
	    			 " detalle gasto="+new ProcesadorSMS().procesarScotiaBank(cur.getString(bodyColumn))+"\n";         
	      }
	      if(cur.getString(2).equals("595") ){
	    	  sms += "From : BBVA : Importe S/. " +
	    			 ( new ProcesadorSMS().extraerImporte(cur.getString(bodyColumn)))+
	    			 " fecha="+sdf.format(new Date(Long.parseLong(cur.getString(dateColumn)))).toString()+
	    			 " detalle gasto="+new ProcesadorSMS().procesarBBVA(cur.getString(bodyColumn))+"\n";         
	      }
	     }
	     System.out.println(sms);
	     view.setText(sms);
	     setContentView(view);
	}
}
